package com.ayoka.parenting.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.CircleGroupBean;
import com.jincp.common.brvah.BaseQuickAdapter;
import com.jincp.common.brvah.BaseViewHolder;
import com.jincp.common.utils.StringUtil;
import com.jincp.image.load.ImageLoader;

/**
 * Created by jinchunping on 2018/4/11.
 */

public class CircleGroupAdapter extends BaseQuickAdapter<CircleGroupBean, BaseViewHolder> {

    public CircleGroupAdapter() {
        super(R.layout.item_circle_group);
    }

    @Override
    protected void convert(BaseViewHolder holder, CircleGroupBean item) {
        ImageLoader.getInstance().displayImage(item.Img, (ImageView) holder.getView(R.id.iv_picture));
        holder.setText(R.id.tv_title, item.Title)
                .setText(R.id.tv_owner, item.FounderName)
                .setText(R.id.tv_join_count, StringUtil.formatString(R.string.format_join_count, item.MemberCount))
                .setVisible(R.id.btn_join_group, !CircleGroupBean.getJoinedStatus(item.JoinedStatus))
                .setVisible(R.id.btn_enter_group, CircleGroupBean.getJoinedStatus(item.JoinedStatus))
                .addOnClickListener(R.id.btn_join_group)
                .addOnClickListener(R.id.btn_enter_group);
    }

    public void notifyCircleGroupChanged(String groupId) {
        for (int i = 0; i < getData().size(); i++) {
            CircleGroupBean circleGroupBean = getData().get(i);
            if (TextUtils.equals(circleGroupBean.ID, groupId)) {
                circleGroupBean.JoinedStatus = 1;
                notifyItemChanged(i + getHeaderLayoutCount());
                break;
            }
        }
    }
}


